package session;

import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import entities.Intern;

@Name("companyManager")
@Scope(ScopeType.CONVERSATION)
public class CompanyManager {

	private String pl;
	private Float agno;
	private String languages;
	private List<Intern> internList;

	@In
	private EntityManager entityManager;

	/**
	 * Arama kriteri agno..
	 */
	public void internResultListAgno() {
		// donen internler icin arrayList..
		ArrayList<Intern> internList = new ArrayList<Intern>();
		// query hazirla..
		Query query = entityManager
				.createQuery("Select i From Intern i Where i.agno > :notOrtalamasi ");
		query.setParameter("notOrtalamasi", agno);
		// listeyi cek..
		List resultList = query.getResultList();

		for (Object object : resultList) {
			internList.add((Intern) object);
		}
		setInternList(internList);
	}

	/**
	 * Arama kriteri programming language..
	 */
	public void internResultListPl() {
		// donen internler icin arrayList..
		ArrayList<Intern> internList = new ArrayList<Intern>();
		// query hazirla..
		Query query = entityManager
				.createQuery("SELECT i FROM Intern i INNER JOIN i.languageList p Where p.name=:plName");
		query.setParameter("plName", pl);
		// listeyi cek..
		List resultList = query.getResultList();

		for (Object object : resultList) {
			internList.add((Intern) object);
		}
		setInternList(internList);
	}

	/**
	 * Company sayfasi icin programlama dilleri yaratir..(kod tekrari var ortak
	 * bir utils sinifindan kullanilabilir)
	 * 
	 * @return
	 */
	public List<SelectItem> getSelectItems() {
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		selectItems.add(new SelectItem("Java", "Java"));
		selectItems.add(new SelectItem("Python", "Python"));
		selectItems.add(new SelectItem("Lisp", "Lisp"));
		selectItems.add(new SelectItem("Cobol", "Cobol"));
		selectItems.add(new SelectItem("Javascript", "Javascript"));
		selectItems.add(new SelectItem("C", "C"));
		selectItems.add(new SelectItem("PL/I", "PL/I"));
		selectItems.add(new SelectItem("Perl", "Perl"));
		return selectItems;
	}

	public String getPl() {
		return pl;
	}

	public void setPl(String pl) {
		this.pl = pl;
	}

	public Float getAgno() {
		return agno;
	}

	public void setAgno(Float agno) {
		this.agno = agno;
	}

	public String getLanguages() {
		return languages;
	}

	public void setLanguages(String languages) {
		this.languages = languages;
	}

	public List<Intern> getInternList() {
		return internList;
	}

	public void setInternList(List<Intern> internList) {
		this.internList = internList;
	}

}
